/*
 * VectorTableModel.java
 *
 * Created on 14 July 2003, 09:04
 * Copyright (C) 2003, Velocityme Partnership
 */

package com.velocityme.client.gui;

import java.util.Vector;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author  Robert Crida Work
 */
public class VectorTableModel extends AbstractTableModel {
    
    /** Array of table columns names */
    final String[] m_columnNames;

    /** Variable number of rows of data */
    final protected Vector m_dataRows;

    /** Creates a new instance of VectorTableModel */
    public VectorTableModel(String[] columnNames) {
        m_columnNames = columnNames;
        m_dataRows = new Vector();
    }
    
    public void removeAllRows() {
        int lastRow = m_dataRows.size();
        if (lastRow > 0) {
            m_dataRows.clear();
            fireTableRowsDeleted(0, lastRow);
        }
    }
    
    public void removeRows(int firstRow, int lastRow) {
        if (firstRow <= lastRow && firstRow >= 0 && lastRow < getRowCount())
            for (int row = lastRow; row >= firstRow; row--)
                m_dataRows.remove(row);
        fireTableRowsDeleted(firstRow,lastRow);
    }
    
    public int getColumnCount() {
        return m_columnNames.length;
    }
    
    public int getRowCount() {
        if (m_dataRows == null)
            return 0;
        else
            return m_dataRows.size();
    }
    
    public String getColumnName(int col) {
        return m_columnNames[col];
    }

    public Object getValueAt(int row, int col) {
        return ((Object[])(m_dataRows.elementAt(row)))[col];
    }

    public Class getColumnClass(int c) {
        Object object = getValueAt(0, c);
        if (object != null)
            return object.getClass();
        else
            return Object.class;
    }
    
}
